package com.ruoyi.project.jiaqin.advertising.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.advertising.domain.Advertising;
import com.ruoyi.project.jiaqin.advertising.service.IAdvertisingService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 广告投放Controller
 *
 * @author admin
 * @date 2021-01-11
 */
@Controller
@RequestMapping("/jiaqin/advertising")
public class AdvertisingController extends BaseController
{
    private String prefix = "jiaqin/advertising";

    @Autowired
    private IAdvertisingService advertisingService;

    @RequiresPermissions("jiaqin:advertising:view")
    @GetMapping()
    public String advertising()
    {
        return prefix + "/advertising";
    }

    /**
     * 查询广告投放列表
     */
    @RequiresPermissions("jiaqin:advertising:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Advertising advertising)
    {
        startPage();
        List<Advertising> list = advertisingService.selectAdvertisingList(advertising);
        return getDataTable(list);
    }

    /**
     * 导出广告投放列表
     */
    @RequiresPermissions("jiaqin:advertising:export")
    @Log(title = "广告投放", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Advertising advertising)
    {
        List<Advertising> list = advertisingService.selectAdvertisingList(advertising);
        ExcelUtil<Advertising> util = new ExcelUtil<Advertising>(Advertising.class);
        return util.exportExcel(list, "advertising");
    }

    /**
     * 新增广告投放
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告投放
     */
    @RequiresPermissions("jiaqin:advertising:add")
    @Log(title = "广告投放", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Advertising advertising)
    {
        return toAjax(advertisingService.insertAdvertising(advertising));
    }

    /**
     * 修改广告投放
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Advertising advertising = advertisingService.selectAdvertisingById(id);
        mmap.put("advertising", advertising);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告投放
     */
    @RequiresPermissions("jiaqin:advertising:edit")
    @Log(title = "广告投放", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Advertising advertising)
    {
        return toAjax(advertisingService.updateAdvertising(advertising));
    }

    /**
     * 删除广告投放
     */
    @RequiresPermissions("jiaqin:advertising:remove")
    @Log(title = "广告投放", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(advertisingService.deleteAdvertisingByIds(ids));
    }
}
